package com.core.utility;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.core.utility.Types.Bathroom;
import com.core.utility.Types.Bedroom;
import com.core.utility.Types.ConstructionType;
import com.core.utility.Types.Furnished;
import com.core.utility.Types.LocalityType;
import com.core.utility.Types.MeasurementType;
import com.core.utility.Types.Month;
import com.core.utility.Types.Ownership;
import com.core.utility.Types.PriceRange;
import com.core.utility.Types.PriceType;
import com.core.utility.Types.TransactionType;
import com.core.utility.Types.Year;

public class TypeUtil {
	public static List<PropertyTypes> getPropertyTypes()
	{
		
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<PropertyTypes> result = session.createQuery("from PropertyTypes").list();
		 System.out.println("Size of PropertyTypes "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
	}
	public static  List<City> getCities()
	{
		
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<City> result = session.createQuery("from City").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
	}
	
	public static List<LocalityType> getLocalityType()
	{
		
		
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<LocalityType> result = session.createQuery("from Types$LocalityType").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
		
	}
	
	
	public static List<TransactionType> getTransactionType()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<TransactionType> result = session.createQuery("from Types$TransactionType").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
	}
	
	public static List<ConstructionType> getConstructionType()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<ConstructionType> result = session.createQuery("from Types$ConstructionType").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
		
	}
	
	public static List<Bathroom>  getBathroom()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<Bathroom> result = session.createQuery("from Types$Bathroom").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
		
	}
	
	public static List<Bedroom> getBedrooms()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<Bedroom> result = session.createQuery("from Types$Bedroom").list();
		 System.out.println("Size of bedroom "+result.size());
		 session.getTransaction().commit();
		 
		 
		
		return result;
		
		
	}
	
	public static List<Furnished> getFurnishedType()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<Furnished> result = session.createQuery("from Types$Furnished").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 return result;
		
	}
	// MeasurementType
	
	public static List<MeasurementType> getMeasurementType()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<MeasurementType> result = session.createQuery("from Types$MeasurementType").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 return result;
		
	}
	// Ownership
	
	public static List<Ownership> getOwnership()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<Ownership> result = session.createQuery("from Types$Ownership").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 return result;
		
	}
	  // PriceType
	public static List<PriceType> getPriceType()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<PriceType> result = session.createQuery("from Types$PriceType").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 return result;
		
	}
	// PriceRange
	
	public static List<PriceRange> getPriceRange()
	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		 List<PriceRange> result = session.createQuery("from Types$PriceRange").list();
		 System.out.println("Size of city "+result.size());
		 session.getTransaction().commit();
		 return result;
		
	}
	
// PriceRange
	
	public static List<Month> getMonth()
	{
		List<Month> list = new ArrayList<Month>();
		String strMonth[]={"January","February","March","April","May","Jun","July","August","September","October","November","Decmber"};
		Month lt ;
		for (int i = 0; i < 12; i++) {
			
		lt= new Types().new Month();
		lt.setMonthValue(i+1);
		lt.setMonthName(strMonth[i]);
		list.add(lt);
		}
		return list;
		
	}
	
	public static List<Year> getYear()
	{
		List<Year> list = new ArrayList<Year>();
		Year lt;
		for (int i = 0; i < 5; i++) {
		lt= new Types().new Year();
		lt.setId(2010+i);
		lt.setYearName(""+(2010+i));
		list.add(lt);
		}
		return list;
		
	}
	

}
